package ar.com.raulsanchez.syncrolist;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;

import android.util.Log;

public class WebServiceInterface {

	private static final String NAMESPACE = "xsd:syncrolist";
	private static final String URL = "http://www.raulsanchez.com.ar/syncrolist/webservice.php";

	// LOGIN
	public String login(String username, String password) {
		final String ACTION = "login";
		
    	SoapObject request = new SoapObject(NAMESPACE, ACTION);
    	request.addProperty("username", username);
 		request.addProperty("password", password);
 		
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        //androidHttpTransport.debug = true;

        try {
            androidHttpTransport.call(URL + "/" + ACTION, envelope);
            SoapObject response = (SoapObject)envelope.bodyIn;
            return response.getProperty(0).toString();
        }
        catch (Exception e) {
        	Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
            e.printStackTrace();
            return "0";
        }
	} // function login
	
	// LISTACTIVITIES
	public String listActivities(Integer usuario_id) {
		final String ACTION = "listActivities";
		
    	SoapObject request = new SoapObject(NAMESPACE, ACTION);
    	request.addProperty("usuario_id", usuario_id);
 		
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        //androidHttpTransport.debug = true;

        try {
            androidHttpTransport.call(URL + "/" + ACTION, envelope);
            SoapObject response = (SoapObject)envelope.bodyIn;
            return response.getProperty(0).toString();
        }
        catch (Exception e) {
        	Log.e("Error : " , "Error on soapPrimitiveData() " + e.getMessage());
            e.printStackTrace();
            return "0";
        }
	} // function listActivities
	 
} // class WebServiceInterface
